import subprocess
import sys


def install_packages():
    packages = [
        'pandas',
        'jieba',
        'wordcloud',
        'matplotlib',
        'requests',
        'seaborn',
        'scipy',
        'numpy',
        "fake_useragent"
    ]
    mirror = 'https://pypi.tuna.tsinghua.edu.cn/simple'

    for package in packages:
        try:
            subprocess.check_call([
                sys.executable,
                '-m',
                'pip',
                'install',
                '--upgrade',
                '--index-url', mirror,
                package
            ])
            print(f"成功安装 {package}")
        except subprocess.CalledProcessError as e:
            print(f"安装 {package} 失败: {e}")


if __name__ == "__main__":
    install_packages()